/**
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *	
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package com.brightcove.android.oneplanet;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * This Activity displays the videos for a playlist.
 */
public class Videos extends ListActivity {
	private final static String TAG = "Videos";
	
	public final static String PLAYLIST_NAME = "playlistName";
	public final static String VIDEO_IDS = "videoIds";
	public final static String VIDEO_NAMES = "videoNames";
	public final static String THUMBNAILS = "thumbnailUrls";

	private AndroidPlaylist playlist;
	
	/**
     * This method is called when a ListView item is clicked / touched
     */
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		Log.d(TAG, "clicked: " + playlist.getVideoName(position));
		Intent i = new Intent(this, Player.class);
		i.putExtra(Player.VIDEO_ID, playlist.getVideoId(position));
		startActivity(i);
	}

	/** 
     * Called when the activity is first created. 
     */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.videos);
		
		playlist = (AndroidPlaylist) getIntent().getSerializableExtra(AndroidPlaylist.PLAYLIST);
		ListAdapter adapter = new VideosAdapter<String>(this, 
				android.R.layout.simple_list_item_1, 
				playlist);
		setListAdapter(adapter);
		setTitle(playlist.getName());
	}
}
